<?php
namespace BoxEdu\Controller\Home;
//use Think\Controller;

class AskController extends CommonController {

	public function _initialize() {
		//
		//dump(date("Y-m-d H:i:s",1474437988));
		parent::_initialize();
	}
	//操作当为空的时候
	public function _empty($name) {
		ob_start();
		$GLOBALS['GETCONTENT'] = 1;
		A("BoxSns/Home/Ask")->$name();
		$this->page_content = ob_get_contents();
		ob_end_clean();
		C('DEFAULT_MODULE', "BoxEdu");
		$this->nav_cur = "Ask";
		$templateFile = $this->getTemplateFile("Index/home");
		parent::display($templateFile);
	}

	/********问题详细***/
	public function ask_show() {
		$id = I('topic_id');
		$this->data = BoxModel("SnsTopic")->load($id);
		$comment_data = BoxModel("SnsComment")->get("ask", "pid='$id'", 5, "comment_id"); //评论列表
		$this->comment_data = $comment_data['list'];
		//dump($this->comment_data);
		$this->show_page($comment_data['pager']);
		// dump($comment_data);
		$this->display();
	}

	/******提问***/
	public function add() {
		if ($this->user_info['ask_num'] > 0) {
			if ($this->knowsid = I('knowsid')) {
				$data = BoxModel("edu_knows")->find($this->knowsid);
				$this->title = "在" . $data['knows'] . "中提问";
				$this->sectionid = $data['knowssectionid'];
				$sectiondata = BoxModel("edu_sections")->load($this->sectionid);
				$this->subjectid = $sectiondata['sectionsubjectid'];
			}
			$this->display();
		} else {
			$this->jump("你目前没有提问次数");
		}
	}

	/******提问***/
	public function do_add() {
		$data = Logic("BoxEdu", "Ask")->add(I());
		echo json_encode($data);
	}

	/********回复问题***/
	public function ask_comment() {
		$this->pid = I('topic_id');
		$this->comment_id = I('comment_id');
		$this->data = BoxModel("SnsTopic")->load($this->pid);
		if ($this->comment_id) {
			$data = BoxModel("SnsComment")->load("ask", $this->comment_id);
			if ($data) {
				$this->pid = $data['pid'];
				$this->data = $data['pidData'];
			}
		}
		$this->display();
	}

	/********回答***/
	public function do_ask_comment() {
		$row = array(
			'content' => I('content'), //必填
			'pid' => I('pid'),
			'type' => 'ask', //
			'to_comment_id' => I('comment_id'),
		);
		$r = Logic('BoxSNS', 'Comment')->add($row);
		exit("$r");
	}

	/******采纳回答***/
	public function accept() {
		$id = I('id');
		$r = Logic('BoxEdu', 'Ask')->accept($id);
		echo json_encode($r);

	}

}